package com.dognessnetwork.customer.service.impl;

import com.dognessnetwork.customer.domain.ChatRoom;
import com.dognessnetwork.customer.domain.Comment;
import com.dognessnetwork.customer.domain.RoomStatus;
import com.dognessnetwork.customer.repository.ChatRoomRepository;
import com.dognessnetwork.customer.service.api.ChatRoomService;
import com.dognessnetwork.customer.service.api.CommentService;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
/**
 * = ChatRoomServiceImpl TODO Auto-generated class documentation
 *
 */
public class ChatRoomServiceImpl implements ChatRoomService {
    @Override
    public ChatRoom findBySeat(String seat) {
        ChatRoom chatRoom = getChatRoomRepository().findBySeat(seat);
        return chatRoom;
    }

    @Override
    public ChatRoom findByPetUser(String petUserName) {
        ChatRoom chatRoom = getChatRoomRepository().findByPetUser(petUserName);
        return chatRoom;
    }

    @Override
    public ChatRoom findBySeatAndPetUser(String seat, String petUserName) {
        ChatRoom chatRoom = getChatRoomRepository().findBySeatAndPetUser(seat, petUserName);
        return chatRoom;
    };

	/**
     * TODO Auto-generated attribute documentation
     * 
     */
    private ChatRoomRepository chatRoomRepository;

	/**
     * TODO Auto-generated attribute documentation
     * 
     */
    private CommentService commentService;

	/**
     * TODO Auto-generated constructor documentation
     * 
     * @param chatRoomRepository
     * @param commentService
     */
    @Autowired
    public ChatRoomServiceImpl(ChatRoomRepository chatRoomRepository, @Lazy CommentService commentService) {
        setChatRoomRepository(chatRoomRepository);
        setCommentService(commentService);
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return ChatRoomRepository
     */
    public ChatRoomRepository getChatRoomRepository() {
        return chatRoomRepository;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param chatRoomRepository
     */
    public void setChatRoomRepository(ChatRoomRepository chatRoomRepository) {
        this.chatRoomRepository = chatRoomRepository;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return CommentService
     */
    public CommentService getCommentService() {
        return commentService;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @param commentService
     */
    public void setCommentService(CommentService commentService) {
        this.commentService = commentService;
    }




	/**
     * TODO Auto-generated method documentation
     * 
     * @param chatRoom
     */
    @Transactional
    public void delete(ChatRoom chatRoom) {
        // Clear bidirectional one-to-many parent relationship with Comment
        for (Comment item : chatRoom.getComment()) {
            item.setChatRoom(null);
        }
        
        getChatRoomRepository().delete(chatRoom);
    }



	/**
     * TODO Auto-generated method documentation
     * 
     * @param entity
     * @return ChatRoom
     */
    @Transactional
    public ChatRoom save(ChatRoom entity) {
        return getChatRoomRepository().save(entity);
    }



	/**
     * TODO Auto-generated method documentation
     * 
     * @return List
     */
    public List<ChatRoom> findAll() {
        return getChatRoomRepository().findAll();
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return Long
     */
    public long count() {
        return getChatRoomRepository().count();
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return Class
     */
    public Class<ChatRoom> getEntityType() {
        return ChatRoom.class;
    }

	/**
     * TODO Auto-generated method documentation
     * 
     * @return Class
     */
    public Class<Long> getIdType() {
        return Long.class;
    }
	/**
     * TODO Auto-generated method documentation
     * 
     * @param seat
     * @param petUser
     * @param status
     * @param pageable
     * @return Page
     */
    public Page<ChatRoom> findBySeatAndPetUserAndStatus(String seat, String petUser, RoomStatus status, Pageable pageable) {
        return getChatRoomRepository().findBySeatAndPetUserAndStatus(seat, petUser, status, pageable);
    }
	/**
     * TODO Auto-generated method documentation
     * 
     * @param seat
     * @param pageable
     * @return Page
     */
    public Page<ChatRoom> findBySeat(String seat, Pageable pageable) {
        return getChatRoomRepository().findBySeat(seat, pageable);
    }

}
